package br.pucrs.prototipoonline.xml.modelos;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;


/**
 * 
 * @author Ricardo Luckei
 * @author Gelson Gentil
 *
 */
public class XMIModelos {
	private static String content = null;
	private static String actionState = null;
	private static String transition = null;
	private static String transitions = null;
	
	
	private static String carregaModelo(String nome) {
		try {
			InputStream is = XMIModelos.class.getResourceAsStream(nome + ".xmi");
			BufferedReader reader = new BufferedReader(new InputStreamReader(is));
			
			StringBuffer buff = new StringBuffer();
			String line = null;
			
			while((line=reader.readLine())!=null) {
				
				//TODO essa é um gambiarra temporaria para remover os caracteres indesejados
				//que aparecem no comeco da string quando lidas do arquivo
				if(line.indexOf("ï»¿")!=-1) {
					line = line.replaceAll("ï»¿","");
				}
				buff.append(line).append("\n");
			}
			
			is.close();
			reader.close();
			
			return buff.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";
	}
	
	
	
	public static String getModeloContent() {
		if(content == null) {
			content = carregaModelo("content");
		}

		return content;
	}

	public static String getModeloActionState() {
		if(actionState == null) {
			actionState = carregaModelo("actionstate");
		}

		return actionState;
	}

	public static String getModeloTransition() {
		if(transition == null) {
			transition = carregaModelo("transition");
		}

		return transition;
	}
	
	public static String getModeloTransitions() {
		if(transitions == null) {
			transitions = carregaModelo("transitions");
		}

		return transitions;
	}
}
